/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ig.formato.util;

import java.lang.reflect.Constructor;
import java.util.Locale;
import java.util.ResourceBundle;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.util.JRClassLoader;
import net.sf.jasperreports.view.JRSaveContributor;
import net.sf.jasperreports.view.JRViewer;

/**
 *
 * @author jsanchez
 */
public class IGFormatoJasperViewe extends JRViewer {

    public IGFormatoJasperViewe(JasperPrint jasperPrint) {
        super(jasperPrint);
    }

    @Override
    protected void initSaveContributors() {
        super.initSaveContributors();
        final String[] DEFAULT_CONTRIBUTORS = {
            //"net.sf.jasperreports.view.save.JRPrintSaveContributor",
            "net.sf.jasperreports.view.save.JRPdfSaveContributor",
            "net.sf.jasperreports.view.save.JRRtfSaveContributor",
            "net.sf.jasperreports.view.save.JROdtSaveContributor",
            "net.sf.jasperreports.view.save.JRHtmlSaveContributor",
            "net.sf.jasperreports.view.save.JRSingleSheetXlsSaveContributor",
            "net.sf.jasperreports.view.save.JRMultipleSheetsXlsSaveContributor",
        //"net.sf.jasperreports.view.save.JRCsvSaveContributor",
        //"net.sf.jasperreports.view.save.JRXmlSaveContributor",
        //"net.sf.jasperreports.view.save.JREmbeddedImagesXmlSaveContributor"
        };

        for (int i = 0; i < DEFAULT_CONTRIBUTORS.length; i++) {
            try {
                Class saveContribClass = JRClassLoader.loadClassForName(DEFAULT_CONTRIBUTORS[i]);
                Constructor constructor = saveContribClass.getConstructor(new Class[]{Locale.class, ResourceBundle.class});
                JRSaveContributor saveContrib = (JRSaveContributor) constructor.newInstance(new Object[]{getLocale(), resourceBundle});
                saveContributors.add(saveContrib);
            } catch (Exception e) {
            }
        }
    }

    @Override
    protected void initResources(Locale locale, ResourceBundle resBundle) {
        super.initResources(locale, resBundle);
        if (locale != null) {
            setLocale(locale);
        } else {
            setLocale(Locale.getDefault());
        }
        if (resBundle == null) {
            ResourceBundle resourceBundle = ResourceBundle.getBundle("net/sf/jasperreports/view/viewer", getLocale());
        } else {
            this.resourceBundle = resBundle;
        }
    }
    
    private ResourceBundle resourceBundle = null;

}
